﻿using GalaSoft.MvvmLight;

namespace Budgetsch.WP7.ViewModel.Comment
{
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using System.Data.Services.Client;

    using Budgetsch.WP7.Model;

    /// <summary>
    /// This class contains properties that a View can data bind to.
    /// <para>
    /// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
    /// </para>
    /// <para>
    /// See http://www.galasoft.ch/mvvm/getstarted
    /// </para>
    /// </summary>
    public class CommentViewModel : ViewModelBase
    {
        /// <summary>
        /// The <see cref="CommentDetailsViewModels" /> property's name.
        /// </summary>
        public const string CommentDetailsViewModelsPropertyName = "CommentDetailsViewModels";

        private ObservableCollection<CommentDetailsViewModel> _commentDetailsViewModels = new ObservableCollection<CommentDetailsViewModel>();

        /// <summary>
        /// Sets and gets the CommentDetailsViewModels property.
        /// Changes to that property's value raise the PropertyChanged event. 
        /// </summary>
        public ObservableCollection<CommentDetailsViewModel> CommentDetailsViewModels
        {
            get
            {
                return _commentDetailsViewModels;
            }

            set
            {
                if (_commentDetailsViewModels == value)
                {
                    return;
                }

                _commentDetailsViewModels = value;
                RaisePropertyChanged(CommentDetailsViewModelsPropertyName);
            }
        }
        /// <summary>
        /// Initializes a new instance of the CommentViewModel class.
        /// </summary>
        /// <param name="incomeComments"></param>
        public CommentViewModel(IEnumerable<WP7DataService.IncomeComment> incomeComments)
        {
            foreach (var comment in incomeComments)
            {
                CommentDetailsViewModels.Add(new CommentDetailsViewModel(comment));
            }
        }

        public CommentViewModel(IEnumerable<WP7DataService.CostComment> incomeComments)
        {
            foreach (var comment in incomeComments)
            {
                CommentDetailsViewModels.Add(new CommentDetailsViewModel(comment));
            }
        }

        public CommentViewModel(IEnumerable<WP7DataService.SavingComment> incomeComments)
        {
            foreach (var comment in incomeComments)
            {
                CommentDetailsViewModels.Add(new CommentDetailsViewModel(comment));
            }
        } 
    }
}